package com.onstar.cn.weight.more;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.onstar.cn.common.util.CommonUtil;
import com.onstar.cn.weight.CustomImageView;
import com.onstar.cn.weight.R;

/**
 * Created by 7828wc on 16/7/15.
 */
public class ImageIconTextLayout extends RelativeLayout {
    private View view;
    private CustomImageView icon_image;
    private TextView tv_text;

    public ImageIconTextLayout(Context context) {
        super(context);
        initView(null);
    }

    public ImageIconTextLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
        initView(attrs);
    }

    public ImageIconTextLayout(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView(attrs);
    }

    private void initView(AttributeSet attrs) {
        view = inflate(getContext(), R.layout.common_image_text, this);
        tv_text = (TextView) view.findViewById(R.id.tv_text);
        icon_image = (CustomImageView) view.findViewById(R.id.icon_image);
    }

    public void setText(String text) {
        if (!CommonUtil.isNull(text)) {
            tv_text.setText(text);
        }
    }

    public void setText(int resId) {
        setText(getContext().getString(resId));
    }

    public void setIcon(int resId) {
        if (resId != -1) {
            icon_image.setImageResource(resId);
        }
    }
}
